package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter@Getter
public class Cart extends BaseDomain{

    public static final Integer STATE_SUCCESS = 1; //成功交易
    public static final Integer STATE_UNDETERMINED = 0; //待定

    private Long userId;

    private Goods goods;

    private BigDecimal price;

    private Integer count = 1;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date addTime;

    private Long addressId;

    private Integer state = STATE_UNDETERMINED;

    public BigDecimal getPrice(){
        return this.price = this.goods.getPrice().multiply(new BigDecimal(""+this.count));
    }

    public Object getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
       map.put("goodsTitle",goods.getTitle());
       map.put("price",price);
       map.put("count",count);
        return JSON.toJSONString(map);
    }

    public String getAddTimeString(){
        return DateUtil.formatDate2(addTime);
    }

    public String getCountString(){
        return ""+count;
    }

}